package com.ygo.feihua;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ListView;
import cn.bmob.v3.BmobQuery;
import cn.bmob.v3.BmobUser;
import cn.bmob.v3.exception.BmobException;
import cn.bmob.v3.listener.FindListener;
import com.ygo.feihua.BmobTable.Kadian;
import com.ygo.feihua.BmobTable.MyUser;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import android.support.v4.util.*;
import com.ygo.feihua.Management.*;

public class KadianShenhe extends AppCompatActivity
{
	ListView kd_sh_list;
	List<Map<String,Object>> data=new ArrayList<Map<String,Object>>();;
	Kdshitem ki;
	Gongju gj;
	private UserManagement um;
	
	@Override
	protected void onCreate(Bundle savedInstanceState)
	{
		// TODO: Implement this method
		super.onCreate(savedInstanceState);
		setContentView(R.layout.kadian_shenhe);
		gj=Gongju.getdx(KadianShenhe.this);
		um=UserManagement.getDx();
		kd_sh_list=(ListView) findViewById(R.id.kd_sh_list);
		gj.cshToolbar((Toolbar) findViewById(R.id.toolbar),"卡店审核");
		
		if(um.getUser()!=null){
			BmobQuery<Kadian> kd=new BmobQuery<Kadian>();
			kd.addWhereEqualTo("kduser",um.getUser());
			kd.order("-updatedAt");
			kd.findObjects( new FindListener<Kadian>(){

					@Override
					public void done(List<Kadian> p1, BmobException p2)
					{
						if(p2==null){
							for(Kadian kdd:p1){

								Map<String,Object> map=new 	ArrayMap<String,Object>();
								map.put("name",kdd.getKd_name());
								map.put("dz",kdd.getKd_dz());
								int s=kdd.getKdsh();
								map.put("sh",s);
								if(s==3){
									map.put("yy",kdd.getKd_yy());
								}
								data.add(map);

							}
							ki=new Kdshitem(KadianShenhe.this,data);
							kd_sh_list.setAdapter(ki);
							
						}else{
							gj.toastBmobException(kd_sh_list,"添加失败",p2);
							
							//gj.show("查询失败"+p2);
						}
						// TODO: Implement this method
					}
				
				});
		}else{
			gj.show("喵还没登录哦~");
			um.logInUser(this);
		//	startActivity(new Intent(KadianShenhe.this,YonghuZhuce.class));
			finish();
		}
	}
}
